package base;

class Book {
	private String isbn;
    private String title;
    private String author;
    private String publisher;
    private boolean isBorrowed;

    public Book(String isbn, String title, String author, String publisher) {
        this.isbn = isbn;
        this.title = title;
        this.author = author;
        this.publisher = publisher;
        this.isBorrowed = false;
    }

    public String getIsbn() { return isbn; }
    public String getTitle() { return title; }
    public boolean isBorrowed() { return isBorrowed; }

    public void borrow() throws BookAlreadyBorrowedException {
        if (isBorrowed) {
            throw new BookAlreadyBorrowedException("图书《" + title + "》已被借出！");
        }
        isBorrowed = true;
    }

    public void returnBook() {
        isBorrowed = false;
    }

    @Override
    public String toString() {
        return String.format("[%s]《%s》 作者：%s 出版社：%s 状态：%s",
                isbn, title, author, publisher, isBorrowed ? "已借出" : "可借");
    }
}
